﻿using System;
using UtfprLibrary.Exceptions;

namespace UtfprLibrary.Extensions {
    public static class ExceptionExtensions {
        /// <summary>
        /// Gets all exceptions messages.
        /// </summary>
        /// <param name="exception">The exception</param>
        /// <returns>Messages from all inner exceptions.</returns>
        /// <exception cref="UtfprLibrary.Exceptions.UtfprExtensionsException">Thrown when an exception occurs.</exception>
        public static string GetAllExceptionMessages(this Exception exception) {
            try {
                Exception inner = exception.InnerException;
                string messages = string.Format("<type:{0}> msg:{1} # \n", exception.GetType().Name, exception.Message);

                while (inner != null) {
                    string.Format("<type:{0}> msg:{1} # \n", inner.GetType().Name, inner.Message);
                    inner = inner.InnerException;
                }

                return messages;
            } catch (Exception ex) {
                throw new UtfprExtensionsException(Properties.Resources.Extensions_ExceptionExtensions_ExMsg_GetAllExceptionMessages, ex);
            }
        }
    }
}
